package edu.nf.dbutil.result;

import edu.nf.dbutil.ResultSetHandler;
import edu.nf.dbutil.RowProcessor;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author yang
 * @date 2024-05-09
 */
public class BeanHandler2<T> implements ResultSetHandler<T> {
    private final Class<T> beanClass;

    public BeanHandler2(Class<T> beanClass) {
        this.beanClass = beanClass;
    }

    /**
     * 将一条记录转换为实体对象
     * @param rs 结果集对象
     * @return
     * @throws SQLException
     */
    @Override
    public T handle(ResultSet rs) throws SQLException {
        return rs.next() ? RowProcessor.toBean2(rs, beanClass) : null;
    }
}
